package forum.repository;

import forum.domain.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/4/1.
 */
//@Repository
public interface RoleRepository extends JpaRepository<Role, Integer>, JpaSpecificationExecutor<Role> {

    @Query(value ="select * from role,user_role where user_role.roleid=role.roleid and user_role.userid = ?1", nativeQuery = true)
    List<Role> getRolesByUserId(Integer id);

    List<Role> findByRolename(String name);

    @Transactional
    @Modifying
    @Query(value ="delete from user_role where user_role.roleid = ?1", nativeQuery = true)
    void deleteByRoleid(Integer id);

}
